package com.guowen.myaccount.utils;

import androidx.annotation.NonNull;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.guowen.myaccount.MainActivity;
import com.guowen.myaccount.R;

public class PasswordDialog extends Dialog implements View.OnClickListener{

    public static String pd = "123456";
    private EditText passwordEt;
    private Button sureBtn;

    public PasswordDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_password);

        passwordEt = findViewById(R.id.dialog_password_pd);
        sureBtn = findViewById(R.id.dialog_password_sure);


        sureBtn.setOnClickListener(this);
    }

    private void login() {
        String password = passwordEt.getText().toString().trim();
        if (!password.equals(pd)){
            Toast.makeText(getContext(),"密保错误！",Toast.LENGTH_SHORT).show();
            return;
        }
        // 修改用户全局变量
        MainActivity.userId = 1;
        Intent intent = new Intent(getContext(),MainActivity.class);
        getContext().startActivity(intent);
        cancel();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_password_sure:
                login();
                break;
        }
    }
}